<?php
 
/*
 * Following code will update a product information
 * A product is identified by product id (pid)
 */
 
// array for JSON response
$response = array();
 
// check for required fields
if (isset($_POST['place_id'])
	&& isset($_POST['place_name']) 
	&& isset($_POST['address'])) {
		$place_id 		= $_POST['place_id'];      
        $place_name 	= $_POST['place_name'];
		$address  		= $_POST['address'];
		$longitude 		= $_POST['longitude']; 
		$latitude      	= $_POST['latitude'];
		$district_id   	= $_POST['district_id'];
		$phone_number  	= $_POST['phone_number'];
		$fax_number    	= $_POST['fax_number'];
		$email         	= $_POST['email'];
		$website       	= $_POST['website'];
		$open_time     	= $_POST['open_time'];
		$close_time    	= $_POST['close_time'];
		$lowest_price  	= $_POST['lowest_price'];
		$hightest_price	= $_POST['hightest_price'];
		$description   	= $_POST['description'];
		$url_avatar     = $_POST['url_avatar'];
		$name_avatar    = $_POST['name_avatar'];
 
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
 
    // connecting to db
    $db = new DB_CONNECT();
 
    // mysql update row with matched pid
    $result = mysql_query("UPDATE Place SET
										place_name		='$place_name'
										,address		='$address'
										,longitude		='$longitude'
										,latitude		='$latitude'
										,district_id	='$district_id'
										,phone_number	='$phone_number'
										,fax_number		='$fax_number'
										,email			='$email'
										,website		='$website'
										,open_time		='$open_time'
										,close_time		='$close_time'
										,lowest_price	='$lowest_price'
										,hightest_price	='$hightest_price'
										,url_avatar		='$url_avatar'
										,name_avatar	='$name_avatar'
										,description	='$description'
									WHERE place_id 		='$place_id'");
									
    // check if row inserted or not
    if ($result) {
        // successfully updated
        $response["success"] = 1;
        $response["message"] = "Successfully updated.";
 
        // echoing JSON response
        echo json_encode($response);
    } else {
 
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
 
    // echoing JSON response
    echo json_encode($response);
}
?>